<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<head>
<title>模型列表</title>
<script type="text/javascript">
	var $grid;
	$(function() {
		$grid = $("#grid").datagrid($.extend(datagridOption, {
			url : "${ctx}/workflow/activitiModel/dataGrid",
			columns : [ [ {
				field : 'ck',
				checkbox : true
			}, {
				field : 'key',
				title : '模型编码'
			}, {
				field : 'name',
				title : '模型名称'
			}, {
				field : 'version',
				title : '模型版本'
			}, {
				field : 'createTime',
				title : '创建时间'
			}, {
				field : 'lastUpdateTime',
				title : '最后更新时间'
			}, {
				field : 'metaInfo',
				title : '模型定义信息',
			} ] ]
		}));
		$("#add").click(function() {
			$("#fm").form("clear");
			$('#fm').form('load', {
				enable : 1
			});
			$("#dlg").dialog("open").dialog("setTitle", "新增模型");
		});
		$("#edit").click(function() {
			var rowData = $grid.datagrid("getSelected");
			if (rowData == null) {
				$.messager.show({
					msg : "请您先选中行",
					icon : "warning",
					position : "bottomRight"
				});
			} else {
				window.open("${ctx}/service/editor?id=" + rowData.id, "_blank");
			}
		});
		$("#deploy").click(function() {
			var rowData = $grid.datagrid("getSelected");
			if (rowData == null) {
				$.messager.show({
					msg : "请您先选中行",
					icon : "warning",
					position : "bottomRight"
				});
			} else {
				$.get("${ctx}/workflow/activitiModel/deploy/" + rowData.id, function(result) {
					$.messager.show({
						msg : result.msg,
						icon : "info",
						position : "bottomRight"
					});
				}, 'json');
			}
		});
		$("#export").click(function() {
			var rowData = $grid.datagrid("getSelected");
			if (rowData == null) {
				$.messager.show({
					msg : "请您先选中行",
					icon : "warning",
					position : "bottomRight"
				});
			} else {
				window.open("${ctx}/workflow/activitiModel/export/" + rowData.id);
			}
		});
		$("#delete").click(function() {
			var rowData = $grid.datagrid("getSelected");
			if (rowData == null) {
				$.messager.show({
					msg : "您未选中行，无法删除",
					icon : "warning",
					position : "bottomRight"
				});
			} else {
				$.messager.confirm("您确定要进行该操作？", function(c) {
					if (c) {
						$.get("${ctx}/workflow/activitiModel/delete/" + rowData.id, function(result) {
							$.messager.show({
								msg : result.msg,
								icon : "info",
								position : "bottomRight"
							});
							if (result.success) {
								$grid.datagrid("deleteRow", rowData);
							}
						}, 'json');
					}
				});
			}
		});
		$("#search").click(function() {
			$grid.datagrid('load', $("#tt").form("getData"));
		});
	});
	function fn_save() {
		$("#fm").form("submit", {
			url : "${ctx}/workflow/activitiModel/create",
			success : function(data) {
				$.messager.show({
					msg : "保存模型成功",
					icon : "info",
					position : "bottomRight"
				});
				$grid.datagrid("load");
				$("#dlg").dialog('close');
			}
		});
	}
</script>
</head>

<body class="easyui-layout" data-options="fit:true,border:false">
	<div data-options="region:'center',fit:true,border:false">
		<table id="grid">
		</table>
	</div>
	<div id="tt" class="row">
		<div class="col-md-6">
		<form class="form-grid-search form-inline">
				<div class="form-group">
					<input type="text" class="form-control" name="modekey" placeholder="模型编码" />
					<input type="text" class="form-control" name="modelName" placeholder="模型名称" />
				</div>
				<button type="button" id="search" class="btn btn-primary">
					<span class="glyphicon glyphicon-search"></span> 查询
				</button>
			</form>
		</div>
		<div class="col-md-6">
		<button id="add" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-plus"></span> 新增模型
				</button>
				<button id="deploy" type="button" class="btn btn-danger">
					<span class="glyphicon glyphicon-cog"></span> 部署模型
				</button>
				<button id="edit" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-pencil"></span> 编辑模型
				</button>
				<button id="export" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-save"></span> 导出模型
				</button>
				<button id="delete" type="button" class="btn btn-danger">
					<span class="glyphicon glyphicon-minus"></span> 删除模型
				</button>
		</div>
	</div>
	<div id="dlg" class="easyui-dialog" style="width: 325px; height: 285px; padding: 10px 20px"
		data-options="resizable:true,modal:true, buttons:'#dlg-btn',closed:true">
		<form id="fm" method="post">
			<input type="hidden" name="id" />
			<table><!-- zst增加table布局，去除div布局,class="fitem" -->
			<tr>
			<td><label>名称:</label></td>
			<td><input name="name" class="easyui-validatebox" data-options="required:true"></td>
			</tr>
			<tr>
			<td><label>KEY:</label></td>
			<td><input name="key" class="easyui-validatebox" data-options="required:true"></td>
			</tr>
			<tr>
			<td><label>描述:</label></td>
			<td><input name="description" class="easyui-textbox" data-options="multiline:true,width:185,height:60"></td>
			</tr>
			</table>
		</form>
		<div id="dlg-btn">
				<button id="add" type="button" class="btn btn-primary" onclick="fn_save();">
					<span class="glyphicon glyphicon-ok"></span> 保存
				</button>
				<button id="edit" type="button" class="btn btn-primary" onclick="$('#dlg').dialog('close');">
					<span class="glyphicon glyphicon-remove"></span> 取消
				</button>
			</div>
	</div>
</body>
</html>
